/*
 * Copyright (C) 2009 Rafael Fernandes
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.phonebooksharing.android.widgets.header;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.content.Intent;

/**
 * Helper class for the List With Header functionality.
 * 
 * @author <a href="mailto:luizrafael@gmail.com">Rafael Fernandes</a>
 * 
 */
@SuppressWarnings("unchecked")
public class ListWithHeaderHelper {
    public static final String              ITEM_TITLE   = "t";
    public static final String              ITEM_CAPTION = "c";
    public static final String              ITEM_LINE2   = "l";
    public static final String              ITEM_ICON    = "i";
    public static final String              ITEM_OPTION  = "o";
    public static final String              ITEM_COUNTER = "co";
    public static final Map<Integer, Class> options      = new HashMap<Integer, Class>();

    public static void startActivity(Context c, int which) {
        c.startActivity(new Intent(c, options.get(which)));
    }

    /**
     * Creates new entry for the list looking up on localized strings
     * 
     * @param context
     * @param title
     * @param caption
     * @param icon
     * @return Map object with the given params
     */
    public static Map<String, ?> createEntry(Context context, int title, int caption, Integer icon) {
        Context cx = context;
        return createEntry(cx.getString(title), cx.getString(caption), icon);
    }

    public static Map<String, ?> createEntry(String title, String caption, Integer icon) {
        return createEntry(title, null, caption, null, icon, null);
    }
    
    public static Map<String, ?> createEntry(String title, String counter, String caption, Integer icon) {
        return createEntry(title, counter, caption, null, icon, null);
    }
    
    public static Map<String, ?> createEntry(String title, String counter, String caption, String line2, Integer icon, Integer opt) {

        Map<String, Object> i = new HashMap<String, Object>();
        i.put(ITEM_TITLE, title);
        i.put(ITEM_CAPTION, caption);
        i.put(ITEM_LINE2, line2);
        i.put(ITEM_ICON, icon);
        i.put(ITEM_OPTION, opt);
        i.put(ITEM_COUNTER, counter);
        return i;
    }
    
    public static Map<String, ?> createEntry(String title, Integer icon) {
        Map<String, Object> item = new HashMap<String, Object>();
        item.put(ITEM_TITLE, title);
        item.put(ITEM_ICON, icon);
        return item;
    }
}
